# Contributor: Alex Yam <alex@alexyam.com>
# Maintainer: Willow Barraco <contact@willowbarraco.fr>
pkgname=unrealircd
pkgver=6.1.5
pkgrel=0
pkgdesc="internet relay chat daemon (ircd)"
url="https://www.unrealircd.org/"
arch="all"
license="GPL-2.0-or-later"
makedepends="
	argon2-dev
	c-ares-dev
	curl-dev
	jansson-dev
	libnsl-dev
	libsodium-dev
	openssl-dev
	pcre2-dev
	"
pkgusers="unrealircd"
pkggroups="unrealircd"
install="$pkgname.pre-install $pkgname.post-install"
subpackages="$pkgname-doc $pkgname-openrc"
options="!check" # no test suite
source="https://www.unrealircd.org/downloads/unrealircd-$pkgver.tar.gz
	0001.configure-without-running-config.patch
	unrealircd.confd
	unrealircd.initd"

prepare() {
	default_prepare
	#update_config_guess #No update needed for ./autoconf/config.guess
	update_config_sub
}

build() {
	./configure \
		--enable-dynamic-linking \
		--enable-ssl \
		--prefix=/usr \
		--with-bindir=/usr/bin \
		--with-cachedir=/var/lib/unrealircd/cache \
		--with-confdir=/etc/unrealircd \
		--with-controlfile=/var/lib/unrealircd/data/unrealircd.ctl \
		--with-datadir=/var/lib/unrealircd/data \
		--with-docdir=/usr/share/man/unrealircd \
		--with-logdir=/var/log/unrealircd \
		--with-modulesdir=/usr/lib/unrealircd/modules \
		--with-nick-history=2000 \
		--with-permissions=0600 \
		--with-pidfile=/var/lib/unrealircd/run/unrealircd.pid \
		--with-privatelibdir=/usr/lib/unrealircd/private_lib \
		--with-scriptdir=/usr/lib/unrealircd/scripts \
		--with-tmpdir=/var/lib/unrealircd/tmp
	make
}

package() {
	install -dm755 \
		$pkgdir/var/lib/unrealircd/run \
		$pkgdir/usr/lib/unrealircd/scripts \
		$pkgdir/usr/lib/unrealircd/private_lib
	make DESTDIR="$pkgdir" install

	# We repair broken permissions first
	chmod -R 755 \
		"$pkgdir"/etc \
		"$pkgdir"/usr \
		"$pkgdir"/var

	# We then protect those folders
	chmod -R 750 \
		"$pkgdir"/etc/unrealircd \
		"$pkgdir"/var/lib/unrealircd
	chown -R unrealircd:unrealircd \
		"$pkgdir"/etc/unrealircd \
		"$pkgdir"/usr/lib/unrealircd \
		"$pkgdir"/var/lib/unrealircd \
		"$pkgdir"/usr/bin/*

	# remove symlink to source
	rm -v "$pkgdir"/usr/lib/unrealircd/scripts/source

	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
942215005c614c154823ca4049243cbcc927072365bf3b7c8fba6cf4c5b86b255ea96cf97ec6361ddd63f96ea9d36e0eb5eb16a6c41b813c53a0d61a4fa21a6e  unrealircd-6.1.5.tar.gz
532cb2419d2b79685a391113cf1f498417ff46ad545b41e3b9e2153966ba92e21e2ef8dc9010ab491bbc10c7758d38a61a1213caf7eabe1c066ccd12c0a6f13e  0001.configure-without-running-config.patch
40b7b53d628f6775f25edb7a9e5cf12935c9f96b5682733fc18dd2395478574e2ff01bbe8313619f975516517b18a9a1613725c0505fd213d41db94092e045ec  unrealircd.confd
79c87a1ca4b33788516c92e7cf3b1e81030a64687d34c8ec84805c42d12b5835bf06d5fc1918c4a8bda83a0d449818ae4c67cdbdb229e61607796b5d9e4f7e41  unrealircd.initd
"
